#include "SpellMap.h"

void SpellMap::createTrunk()
{
	int nodeNbr = 0;

	char fileName[24] = "Test.txt";

	File file;
	
	fileReader *reader;
	
	file = reader->readFile(fileName);
	
	reader->setSpell(file);

/*	//aligning rank one spells up with proper node on trunk
	float dx1[4];
	float dy1[4];

	//align rank 2 with rank 1
	float dx[4];
	float dy[4];
	
	//align rank 3 with rank 2
	float dx2[4];
	float dy2[4];  

	//assigning translation values
	dx1[0] = (reader.TrunkP.mPointX[4]);
	dy1[0] = reader.TrunkP.mPointY[4];

	dx1[1] = (reader.TrunkP.mPointX[9]);
	dy1[1] = reader.TrunkP.mPointY[9];

	dx1[2] = (reader.TrunkP.mPointX[14]);
	dy1[2] = reader.TrunkP.mPointY[14];

	dx1[3] = (reader.TrunkP.mPointX[19]);
	dy1[3] = reader.TrunkP.mPointY[19];

	//assigning translation values
	for( int i = 0; i < 4; i ++)
	{
		dx[i] = (reader.SpellHolder[i][0].mPointX[9] + dx1[i]);
		dy[i] = (reader.SpellHolder[i][0].mPointY[9] + dy1[i]);

		dx2[i] = (reader.SpellHolder[i][1].mPointX[9] + dx[i]);
		dy2[i] = (reader.SpellHolder[i][1].mPointY[9] + dy[i]);
	}*/



	//D3DXVECTOR3 center = D3DXVECTOR3(32.0f, 32.0f, 0.0f);


	// Pushes the Trunk onto the list to be drawn
	for(int i = 0; i < 20; i++)
	{
		//we are at a node tile
		if(i%5 == 4)
		{
            Node *node = new Node(false);
			Tiles tile((float)reader->TrunkP.mPointX[i], (float) reader->TrunkP.mPointY[i], 0.0f, node);
			trunkTiles.push_back(tile);
			delete node;
			//create spell tree for node
			createSpellTree(reader, nodeNbr);

		}
		else
		{
			Tiles tile((float)reader->TrunkP.mPointX[i], (float) reader->TrunkP.mPointY[i], 0.0f);
			trunkTiles.push_back(tile);
		}

	}

	/*for(int m = 0; m < 4; m++)
	{
		//Pushes Rank 1 onto the list to be drawn
		for(int i = 0; i < 10; i++)
		{		
			Tiles tile((float)reader.SpellHolder[m][0].mPointX[i] + dx1[m], (float) reader.SpellHolder[m][0].mPointY[i] + dy1[m], 0.0f);
			myTiles.push_back(tile);

		}
		
		// Pushes Rank 2 onto the list to be drawn
		for(int i = 0; i < 10; i++)
		{		
			Tiles tile((float)reader.SpellHolder[m][1].mPointX[i] + dx[m], (float) reader.SpellHolder[m][1].mPointY[i] + dy[m], 0.0f);
			myTiles.push_back(tile);
			
		}

		// Pushed Rank 3 onto the list to be drawn
		for(int i = 0; i < 10; i++)
		{		
			
			Tiles tile((float)reader.SpellHolder[m][2].mPointX[i] + dx2[m], (float) reader.SpellHolder[m][2].mPointY[i] + dy2[m], 0.0f);
			myTiles.push_back(tile);
			
		}
	}*/

	//set cursor starting position
	//gameCursorPosition = D3DXVECTOR3(myTiles.front().getX(), myTiles.front().getY(), 0.0f);

	//set iterator
	trunkIterator = trunkTiles.begin();
}

void SpellMap::createSpellTree(fileReader *reader, int nodeNbr)
{

	//aligning rank one spells up with proper node on trunk
	float dx1;
	float dy1;

	//align rank 2 with rank 1
	float dx;
	float dy;
	
	//align rank 3 with rank 2
	float dx2;
	float dy2;  

	//assigning translation values
	dx1 = (reader->TrunkP.mPointX[nodeNbr]);
	dy1 = reader->TrunkP.mPointY[nodeNbr];

	//assigning translation values
	
	dx = (reader->SpellHolder[nodeNbr][0].mPointX[9] + dx1);
	dy = (reader->SpellHolder[nodeNbr][0].mPointY[9] + dy1);

	dx2 = (reader->SpellHolder[nodeNbr][1].mPointX[9] + dx);
	dy2 = (reader->SpellHolder[nodeNbr][1].mPointY[9] + dy);
	
	//Pushes Rank 1 onto the list to be drawn
	for(int i = 0; i < 10; i++)
	{		
		//Node tile((float)reader->SpellHolder[nodeNbr][0].mPointX[i] + dx1, (float) reader->SpellHolder[nodeNbr][0].mPointY[i] + dy1, 0.0f);
//		Branch branchTile((float)reader->SpellHolder[nodeNbr][0].mPointX[i] + dx1, (float) reader->SpellHolder[nodeNbr][0].mPointY[i] + dy1, 0.0f, false);
//		trunkTiles.back().getNode()->spellTree.push_back(branchTile);
		//trunkTiles.back().spellTree.push_back(tile);
		
	}
	
/*	// Pushes Rank 2 onto the list to be drawn
	for(int i = 0; i < 10; i++)
	{		
		Tiles tile((float)reader.SpellHolder[nodeNbr][1].mPointX[i] + dx, (float) reader.SpellHolder[nodeNbr][1].mPointY[i] + dy, 0.0f);
		myTiles.push_back(tile);
		
	}

	// Pushed Rank 3 onto the list to be drawn
	for(int i = 0; i < 10; i++)
	{		
		
		Tiles tile((float)reader.SpellHolder[nodeNbr][2].mPointX[i] + dx2, (float) reader.SpellHolder[nodeNbr][2].mPointY[i] + dy2, 0.0f);
		myTiles.push_back(tile);
		
	}*/
	
}